home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / makemotion.lwm < prev    next >
Text File  |  1993-12-13  |  4KB  |  172 lines

  1. /* CMD: Make Motion
  2.  * Create motion file with user-specified functions of t in each channel
  3.  * By Arnie Cachelin © 1993 NewTek Inc.
  4.  * Tue Jun 22 01:34:00 1993
  5.  */
  6.  
  7. NUMERIC DIGITS 6
  8. call addlib "LWModelerARexx.port", 0
  9. signal on error
  10. signal on syntax
  11. call addlib "rexxsupport.library", 0, -30, 0
  12. MATHLIB="rexxmathlib.library"
  13. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  14.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  15.     call notify(1,"!Can't find "MATHLIB)
  16.     exit
  17.     END
  18.  
  19.  
  20. MFile=getfilename("-- Save Motion --","t:")
  21. if MFile ~="(none)" then File.Name=MFile
  22. else exit
  23. say file.name
  24. sysnam = 'Motion: 'MFile
  25. filnam = 'ENV:Motion.state'
  26. version = 'Motion Maker v1.0'
  27. Frames=30
  28. h=0; p=0; b=0
  29. xsc=1; ysc=1; zsc=1
  30. File.type="LWMO"
  31. SecsPerFrame=1/30
  32. Time=SecsPerFrame*Frames
  33. dt=SecsPerFrame
  34.  
  35. /* Default Motion functions */
  36. FofT.0.0  = "2*t"
  37. FofT.0.1  = "4*sin(360*t)" /* 1hz sine wave */
  38. FofT.0.2  = "0"
  39. FofT.1.0  = "t*90" /* 90 degrees/sec (0.25hz) */
  40. FofT.1.1  = "90"
  41. FofT.1.2  = "(120*t)//60"
  42. FofT.2.0  = "1"
  43. FofT.2.1  = "1 + 0.2*cos(360*t)" /* 1hz cosine wave */
  44. FofT.2.2  = "1 + 0.1*randu()"    /* random fluctuation 10% */
  45.  
  46. if (exists(filnam)) then do
  47.     if (~open(state, filnam, 'R')) then break
  48.     if (readln(state) ~= version) then break
  49.     parse value readln(state) with frames keyspacing .
  50.     do ch=0 to 2
  51.       do i=0 to 2
  52.         FofT.ch.i = readln(state)
  53.       end i
  54.     end ch
  55.     call close state
  56. end
  57.  
  58. call req_begin sysnam
  59.  
  60. id_mes  = req_addcontrol("Make ", 'T', "motion for LW, using your own f(t)")
  61. id_keysp  = req_addcontrol("Key Spacing", 'n')
  62. id_frames = req_addcontrol("Frames ", 'n',0)
  63. id_ch.0.0  = req_addcontrol(" X ", 'S',40)
  64. id_ch.0.1  = req_addcontrol(" Y ", 'S',40)
  65. id_ch.0.2  = req_addcontrol(" Z ", 'S',40)
  66. id_ch.1.0  = req_addcontrol(" H ", 'S',40)
  67. id_ch.1.1  = req_addcontrol(" P ", 'S',40)
  68. id_ch.1.2  = req_addcontrol(" B ", 'S',40)
  69. id_ch.2.0  = req_addcontrol("ScX", 'S',40)
  70. id_ch.2.1  = req_addcontrol("ScY", 'S',40)
  71. id_ch.2.2  = req_addcontrol("ScZ", 'S',40)
  72.  
  73. call req_setval id_frames, Frames
  74. call req_setval id_Keysp, 5
  75. do ch=0 to 2
  76.   do i=0 to 2
  77.     say ch i FofT.ch.i
  78.     call req_setval id_ch.ch.i, FofT.ch.i
  79.     end i
  80.   end ch
  81.  
  82. if (~req_post()) then do
  83.     call req_end
  84.     exit
  85. end
  86.  
  87. frames   = req_getval(id_frames) % 1
  88. KeySpacing = req_getval(id_keysp)
  89. do ch=0 to 2
  90.   do i=0 to 2
  91.     FofT.ch.i  = req_getval(id_ch.ch.i)
  92.     end i
  93.   end ch
  94.  
  95. call req_end
  96.  
  97. if (open(state, filnam, 'W')) then do
  98.     call writeln state, version
  99.     call writeln state, frames keyspacing
  100.     do ch=0 to 2
  101.       do i=0 to 2
  102.         call writeln state, FofT.ch.i
  103.       end i
  104.     end ch
  105.     call close state
  106. end
  107.  
  108. Time=SecsPerFrame*Frames
  109. Keys=1+Frames%KeySpacing
  110. frame=0
  111.  
  112. call meter_begin frames+2, 'Generating Motion'
  113. call WriteHeader(mot,keys)
  114. t=0
  115. do frame=0 to frames
  116.   do ch=0 to 2
  117.     do i=0 to 2
  118.       say 'Val='||FofT.ch.i
  119.       interpret 'Val='||FofT.ch.i
  120.       chan.ch.i = Val
  121.       end i
  122.     end ch
  123.   if frame//KeySpacing=0 then
  124.     call WriteKey(mot,frame,1)
  125.   else if frame=Frames then
  126.     call WriteKey(mot,frame,1)
  127.   t=t+dt
  128.   call meter_step
  129. end
  130. call close mot
  131. call meter_end
  132. call notify(1,'!Created LightWave Motion File: 'File.name)
  133. exit
  134.  
  135. WriteKey:  PROCEDURE  EXPOSE chan.
  136.   arg MotFile, frame, lin
  137.   channels=""
  138.   do ch=0 to 2
  139.     do i=0 to 2
  140.       channels= channels||' '||chan.ch.i
  141.       end i
  142.     end ch
  143.   spline=frame lin "0.0 0.0 0.0"
  144.   say channels spline
  145.   call writeln(MotFile,channels)
  146.   call writeln(MotFile,spline)
  147.   return frame
  148.  
  149. WriteHeader: PROCEDURE EXPOSE File.
  150.   arg MotFile, Keys
  151.   if open(MotFile,File.name,'W') then do
  152.     call writeln(MotFile,File.type)
  153.     call writeln(MotFile,"1") /* magic # */
  154.     call writeln(MotFile,"9") /* Channels */
  155.     call writeln(MotFile,Keys)
  156.   end
  157.   else do
  158.     Bummer("Can't open Motion file : "File.name)
  159.   end
  160.   return 1
  161.  
  162. Bummer:
  163.  ARG etxt
  164.     t=Notify(1,'!Rexx Script Error','@'ETxt)
  165.  exit
  166.  
  167. syntax:
  168. error:
  169.   call end_all
  170.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  171.     exit
  172.